package com.registration.controller;

import com.registration.Annotation.OperateLog;
import com.registration.bean.ReportBean;
import com.registration.service.ReportService;
import com.registration.util.JsonResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/v1")
@CrossOrigin(origins = "*")
public class ReportController {

    @Autowired
    private ReportService reportService;

    /**
     * 获取报告列表
     * @param patientId 就展示该就诊人的报告
     * @param username
     * @param patientName
     * @param checkTime
     * @param reportType
     * @return
     */
    @GetMapping(value="/report", produces = {"application/json"})
    @OperateLog("获取报告列表")
    public JsonResponse getReports(
            @RequestParam(required = false) Integer patientId,
            @RequestParam(required = false) String username,
            @RequestParam(required = false) String patientName,
            @RequestParam(required = false) String checkTime,
            @RequestParam(required = false) String reportType) {

        JsonResponse response = new JsonResponse();

        try {
            List<ReportBean> reports = reportService.getReports(patientId, username, patientName, checkTime, reportType);
            response.setCode(0);
            response.setMsg("查询成功");
            response.setData(reports);
        } catch (Exception e) {
            response.setCode(1);
            response.setMsg("查询失败: " + e.getMessage());
            System.out.println(e.getMessage());
            e.printStackTrace();
        }
        return response;
    }



    /**
     * 根据报告ID获取报告详情
     * @param reportId 报告ID
     * @return 报告详情
     */
    @GetMapping("/report/{id}")
    @OperateLog("获取报告详情")
    public JsonResponse getReportDetail(@PathVariable("id") Integer reportId) {
        JsonResponse response = new JsonResponse();
        try {
            ReportBean report = reportService.getReportById(reportId);
            if (report != null) {
                response.setCode(0);
                response.setMsg("查询成功");
                response.setData(report);
            } else {
                response.setCode(1);
                response.setMsg("未找到相关报告");
            }
        } catch (Exception e) {
            response.setCode(1);
            response.setMsg("查询失败: " + e.getMessage());
        }
        return response;
    }




}